Creating a DriverΒΆ

Creating another driver using the driver model provided for another piece of hardware is fairly trivial at this point, at least as far as utilizing the driver model is concerned. For the first time, start out with something super simple to get your feet wet.

A simple one I can think of would be for an LED.

  1. Create BSPdriversLEDdrv_led.c using BSPdriversMP3drv_mp3.c as a template (or make your own clean driver template)
  2. Create BSPdriversincdrv_led.h using BSPdriversincdrv_mp3.h as a template (or make your own clean driver template)
  3. Make sure the drv_led.h define check is unique/specific to this file. e.g. __DRV_LED_H__
  4. Define a device name. e.g. LED_DRV0
  5. Define the IOCTLs for the driver. e.g. IOCTL_LED_INIT, IOCTL_LED_ON, IOCTL_LED_OFF
  6. Add the prototype(s) for external linkage. In this case just for Led_Init().

For the drv_led.c file:

  1. Provide the necessary includes
  2. Probably only need to support one device for now
  3. Applicable interface functions would be Led_Open, Led_Close, and Led_Ioctl. Maybe Led_Write if you had a bank of LEDs to write to. If you only wanted to turn one LED on or off, then an IOCTL could be used I suppose. An Led_Read could possibly be used to sense the ambient light picked up by the LED, but that would suggest the LED is connected to a pin that goes to an A/D input.
  4. Fill in the code for Led_Init
  5. Fill in the code for Led_Open
  6. Fill in the code for Led_Close
  7. Fill in the code for Led_Ioctl

After a little bit of studying, designing, implementing, debugging, iterating you should be ready to do another one, for example the buttons.

Let us know if you get stuck in a particular area here. It seems a little daunting at first, but after methodically working through your first one, it’s a fairly simple process and kind of nice to abstract to a standardized driver model interface instead of using device specific function calls.

It also helps that for these simple drivers, you’ll already have the peripheral device specific code from previous assignments. It’s almost a copy and paste exercise but you’ll want to do a little up front work (stuyding, designing, implementing) to minimize copy and paste type bugs and pitfalls.

Previous topic

Drivers

Next topic

MP3 Player Driver

This Page